/**
 * 根据给定的属性生成SKU（库存保有单位）
 *
 * @param {Object} attrs - 包含多个属性的对象，用于生成SKU
 * @returns {Array} - 生成的SKU列表
 */
function generateSkus(attrs) {
  const keys = Object.keys(attrs);
  const len = keys.length;
  const result = [];
  if (len === 0) return [];
  function combine(index, template) {
    const key = keys[index];
    const options = attrs[key];
    if (index >= len) return;
    for (const value of options) {
      const obj = { ...template, [key]: value };
      combine(index + 1, obj);
      if (index === len - 1) result.push(obj);
    }
  }
  combine(0, {});
  return result;
}

const attrs = {
  color: ["red", "blue", "green"],
  size: ["small", "medium", "large"],
  shape: ["circle", "square", "triangle"],
};
const result = generateSkus(attrs);
console.log(result);
